<template>
  <customTree
  :data="treeData"
  @click="_click"
  @load="load"
  :isLoading="isLoading"
  :keys="{ value: 'id', label: 'title', children: 'children' }"
  :subHeight="200"
  :expandLevel="0"
  :showNodeOp="true"
  @nodeOpAfter="nodeOpAfter"
  draggable
  ref="customTree"
  >
  </customTree>
</template>

<script>

export default {
  desc: '菜单树-所有',
  name: 'treeMenuAll',
  props: {
    /**
     * @Description：默认选中节点
     * @Date 2023-10-10
     * @param [节点value值]
     */
    defaultActived: {
      type: Array,
      default: () => {
        return [0]
      },
    }
  },
  components: {
  },
  mounted() {
    this.load()
  },
  data() {
    return {
      treeData: [],
      isLoading: false
    }
  },
  methods: {
    // 加载数据
    load() {
      this.isLoading = true
      this.$ajax.get('/program/menu/getList', {
      }).then(response => {
        if (response.code == 0) {
          this.treeData = JSON.parse(response.data.menu)
        } else {
          this.utilMessage.error(response.msg)
        }
        this.$nextTick(() => {
          this.isLoading = false
        })
      })
      setTimeout(() => {
        this.isLoading = false
      }, 10000)
    },

    // 节点点击时触发
    getInst() {
      return this.$refs.customTree
    },

    // 节点点击时触发
    _click(nodeData) {
      this.$emit('click', nodeData)
    },

    /*
     * @Description：更新树节点
     * @Date 2023-10-12
     * @param value 节点标志
     * @param data  节点数据
    */
    nodeUpdate(value, data) {
      this.getInst().nodeUpdate(value, data)
    },

    /*
     * @Description：删除树节点
     * @Date 2023-10-12
     * @param value 节点标志
    */
    nodeRemove(value) {
      this.getInst().nodeRemove(value)
    },

    // 节点操作前置方法
    nodeOpBefore(btnConfig, node) {
      // 父组件后缀方法
      if (this.$parent && this.$parent.nodeOpBefore) {
        return this.$parent.nodeOpBefore(btnConfig, node)
      }
    },

    // 节点操作后置方法
    nodeOpAfter(btnConfig, node, dataNew) {
      // 父组件后缀方法
      if (this.$parent && this.$parent.nodeOpAfter) {
        this.$parent.nodeOpAfter(btnConfig, node, dataNew)
      }
    },

    /*
     * @Description：恢复最后一次操作的节点
     * @Date 2023-10-12
     * @param value 节点标志
    */
    nodeRevertDataLast() {
      this.getInst().nodeRevertDataLast()
    }
  },
  watch: {
  },
  computed: {
  }
}
</script>

<style lang="scss">
</style>
